/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package slicer_20;

import javax.swing.*;

/**
 * Slicer skapar samt öppnar fönstret vårat program använder. Här läggs även menyer till.
 * @author Mikael Köhlmyr | mikael@kohlmyr.com | http://www.kmyr.net
 */
public class Slicer {
    public int width;
    public int height;
    public JFrame window;
    public MyPanel panel;
    public JMenuBar menubar;
    public JMenu menu;

    public Slicer(){
        width = 1000; //+4 644
        height = 700; //+48 522
        initiate();
    }
    
        /**
         * initiate gör i princip vad en konstruktor brukar, den skapar window samt dess menyer med hjälp av variabler som sätts i konstruktorn.
         */
        public void initiate(){
            window = new JFrame("Slicer20 1.0 | 'Hurricane through me'");
            window.setBounds(0, 0, width, height);

            window.setResizable(true);
            window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            menubar = new JMenuBar();
            menu = new JMenu("Actions");
            panel = new MyPanel();

            JMenuItem newSquare = new JMenuItem("New Square");
            newSquare.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    String dimensions = JOptionPane.showInputDialog(null,"Set dimensions (width height)","Create a square",JOptionPane.PLAIN_MESSAGE);
                    if ((dimensions != null) && (dimensions.length() > 0)){
                        panel.newSquare(dimensions);
                    }
                }
            });
            JMenuItem chooser = new JMenuItem("Colorchooser");
            chooser.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    panel.MyCC = new MyColorChooser(panel);
                }
            });
            JMenuItem export = new JMenuItem("Export");
            export.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt){
                    panel.Xport = new Exporter(panel);
                }
            });
            JMenuItem help = new JMenuItem("Help");
            help.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt){
                    JOptionPane.showMessageDialog(null, "Copy & paste: Ctrl c + Ctrl v \n Transform: Ctrl + drag at edge \n Colorchooser: C \n Export: E \n Etc... cba");
                }
            });
            window.add(menubar);
                menubar.add(menu);
                    menu.add(newSquare);
                    menu.add(chooser);
                    menu.add(export);
                    menu.add(help);
            window.setJMenuBar(menubar);
            window.add(panel);

            window.setVisible(true);
        }

}
